<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Linkslists;
use App\Models\Linkslistsqrcodes;
use App\Services\CacheService;
use App\Services\Qrcodedecoder;
use DB,Log;

class Linkqrcodeurl extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'links:qrcode_url';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '获取每个二维码的链接';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        ini_set('memory_limit','1024M');
        DB::table("links_lists_qrcodes")->select("id","img_url")->orderBy("id","DESC")->where("id","<",424929)->where("id",">",400000)->chunk(100, function ($qrcodes) {
            foreach ($qrcodes as $qrcode) {
                dump($qrcode->id);
                $img_url = $qrcode->img_url;
                if(strpos($qrcode->img_url,"http") == false){
                    $img_url = "http:".$qrcode->img_url;
                }
                $qrcode_link = Qrcodedecoder::qrcodeDecoder($qrcode->img_url);
                if (!empty($qrcode_link)) {
                    Linkslistsqrcodes::updateQrcodesLink($qrcode->id,$qrcode_link);
                }
            }
        });
    }
}
